Skip to content

feat!: trap with revert data#5732

Merged
sirasistant merged 15 commits intomasterfrom
arv/trap_with_data
Apr 16, 2024
Merged

feat!: trap with revert data#5732
sirasistant merged 15 commits intomasterfrom
arv/trap_with_data

Conversation

@sirasistant
Copy link
Contributor

@sirasistant sirasistant commented Apr 12, 2024

This PR adds revert data for user-defined messages in the TRAP opcode. Not all messages are returned as revert data, since compiler intrinsic messages are spammed all over SSA and codegening revert data for all those makes brillig function size blow up and impacts performance in a hard way due to deserializing load.
This is currently only for static assert messages, since dynamic ones are implemented as an oracle and probably need a rework to be able to return them as revert data.

@AztecBot
Copy link
Collaborator

AztecBot commented Apr 12, 2024

Benchmark results

Metrics with a significant change:

  • circuit_simulation_time_in_ms (base-parity): 4,123 (+7863%)
  • circuit_simulation_time_in_ms (root-parity): 1,038 (+10253%)
  • note_trial_decrypting_time_in_ms (8): 49.1 (+158%)
  • note_trial_decrypting_time_in_ms (32): 71.0 (+165%)
  • note_trial_decrypting_time_in_ms (64): 104 (+342%)
Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 8 txs 32 txs 64 txs
l1_rollup_calldata_size_in_bytes 772 772 772
l1_rollup_calldata_gas 6,796 (+1%) 6,808 6,808
l1_rollup_execution_gas 587,277 587,289 587,289
l2_block_processing_time_in_ms 1,318 (-8%) 4,788 (-7%) 11,011 (-9%)
note_successful_decrypting_time_in_ms 247 (+13%) 559 (+7%) 986 (+9%)
note_trial_decrypting_time_in_ms ⚠️ 49.1 (+158%) ⚠️ 71.0 (+165%) ⚠️ 104 (+342%)
l2_block_building_time_in_ms 10,778 (+11%) 39,987 (+5%) 85,893 (+13%)
l2_block_rollup_simulation_time_in_ms 10,654 (+12%) 39,575 (+6%) 85,112 (+14%)
l2_block_public_tx_process_time_in_ms 5,181 (-2%) 21,170 (+2%) 47,951 (+15%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 5 blocks 10 blocks
node_history_sync_time_in_ms 14,066 (-4%) 26,950 (-6%)
note_history_successful_decrypting_time_in_ms 1,214 (+7%) 2,315 (+4%)
note_history_trial_decrypting_time_in_ms 52.8 (+26%) 79.6 (+1%)
node_database_size_in_bytes 18,731,088 35,119,184
pxe_database_size_in_bytes 29,859 59,414

Circuits stats

Stats on running time and I/O sizes collected for every circuit run across all benchmarks.

Circuit circuit_simulation_time_in_ms circuit_input_size_in_bytes circuit_output_size_in_bytes
private-kernel-init 149 (-1%) 44,561 26,424
private-kernel-inner 166 (+7%) 72,188 26,424
private-kernel-ordering 114 (+6%) 51,090 39,297
base-parity ⚠️ 4,123 (+7863%) 128 311
root-parity ⚠️ 1,038 (+10253%) 1,244 311
base-rollup 14,106 (+14%) 110,820 957
root-rollup 49.9 (+3%) 4,551 821
public-kernel-app-logic 92.0 (+14%) 48,151 40,933
public-kernel-tail 130 (+7%) 53,644 7,385
merge-rollup 11.8 (-13%) 2,760 957
public-kernel-teardown 79.6 (+2%) 48,151 40,933
public-kernel-setup 78.6 (+1%) 48,151 40,933

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 16 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves 32 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.2 (-8%) 16.0 (-10%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.6 N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.591 (-8%) 0.494 (-10%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 47.7 (-8%) 72.9 (-13%) 233 (-10%) 450 (-10%) 881 (-10%) 1,751 (-14%) N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 96.0 159 543 1,055 2,079 4,127 N/A
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.489 (-8%) 0.448 (-13%) 0.423 (-11%) 0.419 (-11%) 0.418 (-10%) 0.418 (-14%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 56.9 (-5%) 108 (-11%) 339 (-9%) 664 (-10%) 1,314 (-10%) 2,625 (-10%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 105 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.500 (-6%) 0.484 (-11%) 0.459 (-10%) 0.455 (-11%) 0.455 (-10%) 0.455 (-11%) N/A
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A N/A N/A N/A N/A 64.5 (-4%)
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A N/A N/A N/A N/A 109
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A N/A N/A N/A N/A 0.561 (-5%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 41,005 528,889

Transaction size based on fee payment method

Metric native fee payment method fpc_public fee payment method fpc_private fee payment method
tx_with_fee_size_in_bytes 905 1,161 1,377

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms 1,129 (-2%) 802 (+2%) 3,273 (-4%)
Metric 1 public data writes 2 public data writes 3 public data writes 4 public data writes 5 public data writes 8 public data writes
tx_sequencer_processing_time_ms 475 (+5%) 295 (-4%) 749 (-9%) 398 (+2%) 1,217 (-10%) 445 (-4%)

@AztecBot
Copy link
Collaborator

AztecBot commented Apr 12, 2024

Docs Preview

Hey there! 👋 You can check your preview at https://661e2d4ecf80ac0606c61dbc--aztec-docs-dev.netlify.app

rhs,
} => {
assert!(is_integral_bit_size(*bit_size), "BinaryIntOp bit size should be integral: {:?}", brillig_instr);
assert!(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we weren't running cargo fmt on this file :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, I was just working on it but I guess if I run cargo ftm as well I'll be ok :D

@sirasistant sirasistant changed the title feat: trap with data (WIP) feat!: trap with data (WIP) Apr 15, 2024
@sirasistant sirasistant changed the title feat!: trap with data (WIP) feat!: trap with revert data Apr 15, 2024
@sirasistant sirasistant marked this pull request as ready for review April 15, 2024 12:14
@TomAFrench TomAFrench requested a review from vezenovm April 15, 2024 12:29
@fcarreiro fcarreiro removed the request for review from Maddiaa0 April 15, 2024 13:10
rhs,
} => {
assert!(is_integral_bit_size(*bit_size), "BinaryIntOp bit size should be integral: {:?}", brillig_instr);
assert!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, I was just working on it but I guess if I run cargo ftm as well I'll be ok :D

BrilligOpcode::Trap { /*return_data_offset, return_data_size*/ } => {
// TODO(https://github.com/noir-lang/noir/issues/3113): Trap should support return data
BrilligOpcode::Trap {
revert_data_offset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be direct or indirect? I.e., do I have to read from [revert_data_offset, revert_data_offset+size]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct!

Copy link
Contributor Author

@sirasistant sirasistant Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, I was just working on it but I guess if I run cargo ftm as well I'll be ok :D

I think rust-analyzer ships with vscode formatting :D

Copy link
Contributor

@vezenovm vezenovm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits but looks good

@vezenovm
Copy link
Contributor

vezenovm commented Apr 15, 2024

This is currently only for static assert messages, since dynamic ones are implemented as an oracle and probably need a rework to be able to return them as revert data.

We could do this if we support returning a dynamic string in Brillig. I originally held off on adding it for dynamic assertions as to stay in line with ACIR. We have broken away with features in Brillig and ACIR (e.g. break and continue) so I think it would be fine to add this feature.

sirasistant and others added 2 commits April 15, 2024 17:53
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
@sirasistant
Copy link
Contributor Author

We could do this if we support returning a dynamic string in Brillig. I originally held off on adding it for dynamic assertions as to stay in line with ACIR. We have broken away with features in Brillig and ACIR (e.g. break and continue) so I think it would be fine to add this feature.

I'm going to think more on this line because this seems interesting!

@vezenovm
Copy link
Contributor

vezenovm commented Apr 15, 2024

I'm going to think more on this line because this seems interesting!

The reason we didn't resolve format strings in ACIR is because a fmt string resolution would require slices. But perhaps we could avoid a divergence with a better Display interface. We have an issue here for improving how string formatting is handled (noir-lang/noir#4238). We also have considered moving constraint errors to be more generalized and as part of the ABI (noir-lang/noir#4239).

@sirasistant sirasistant enabled auto-merge (squash) April 15, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants